package com.tmxk.springmvc.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;

/* springmvc注解
    @Controller: 标识控制层,加载类头部
    @RequestMapping : 请求路径注解,通常加载在类头部和方法头上
*/
@Controller
public class SpringMVCTestController {

    //定义一个get请求,请求接口名为helloSpringMvc.do
  //  @RequestMapping("helloSpringMvc")
    @RequestMapping(value = "/helloSpringMvc.do",method = RequestMethod.GET)
    public String helloSpringMvc(HttpServletRequest request){
        String str = "初识SpringMVC";
        request.setAttribute("message",str);
        //转发请求方式一:index.jsp
        return "index.jsp";
    }

    @RequestMapping(value = "/hiSpringMvc.do",method = RequestMethod.POST)
    public String hiSpringMvc(){
        //转发请求方式二: forward:index.jsp
        return "forward:/index.jsp";
    }

    @RequestMapping("/redirect/hiSpringMvcRedirect.do")
    public String hiSpringMvcRedirect(HttpServletRequest request){
        //重定向: redirect:/index.jsp
        request.getSession().setAttribute("cdx","重定向数据");
        return "redirect:/index.jsp";
    }
}
